<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
if(!$action)$action = 'list';
$active['players'] = 'active';


if($playerid)
{
    $rs = $db1->query("select * from players where m_id='$playerid'");
    $player = $rs->fetch();
}

if($action=='list')
{
    if($_SERVER['REQUEST_METHOD']=='POST')
    {
        $msg = '';
	$validate = array(
            'm_name' => array('type'=>'string', 'min_length'=>3),
	);
	$result = Validate::multiple($_POST, $validate);
        if(!$result['m_name'])admin_err_page('玩家ID没填写,请重新填写');
        $post = array(
            'm_name' => $m_name,
            'm_race' => $m_race,
            'm_class' => $m_class,
            'm_cmt' => $m_cmt,
            'm_sex' => $m_sex,
        );
        $post = array_map("strip_tags", $post);
        if($player)
        {
            $db1->UpData($post, 'players', array('m_id'=>$player['m_id']));
            admin_ok_page("修改成功,请不要刷新此页面以免出现剑类专精效果.", './?admin/players');
        }
        else
        {
            $rs = $db1->query("select count(*) from players where m_name like '$m_name'");
            if($rs->fetchColumn()>=1)
            {
                admin_err_page('玩家ID已存在,请检查');
                exit();
            }

            $db1->InsertData($post, 'players');
            admin_ok_page("修改成功,请不要刷新此页面以免出现剑类专精效果.", './?admin/players');
        }
    }

    $sql = "select * from races";
    $rs = $db1->query($sql);
    while($row = $rs->fetch())
    {
        $races[$row[race]] = $row;
    }

    $cond = "";
    if($_GET['class'])$cond .= " and m_class='$_GET[class]' ";
    $sql = "select * from players where 1 $cond order by m_id desc";
    $pager = new ShowPage($db1, 25, $sql);
    $sql = $pager->GetNewSql();

    $rs = $db1->query($sql);
    $i = 1;
    while($row = $rs->fetch())
    {
        if($i%2==0)$row['css'] = 'odd';
        $row['icon'] = $classes[$row[m_class]]['c_icon'];
        if($row[m_sex]==3)$row['race_icon'] = $races[$row[m_race]]['icon_f'];
        else $row['race_icon'] = $races[$row[m_race]]['icon_m'];
        $players[] = $row;
        $i++;
    }

    include template('admin/players');
}


?>
